//
//  BBLabel.swift
//  BaoKanSwift
//
//  Created by uncle-R on 16/6/9.
//  Copyright © 2016年 uncle-R. All rights reserved.
//

import UIKit

@objc protocol BBLabelDelegate: NSObjectProtocol{

optional
    func labelClick(label:BBLabel, tag: Int ) -> Void

}

class BBLabel: UILabel {
    
    var delegate :BBLabelDelegate?
    var lastState :Bool?
    var didSelected :Bool?{
        
        didSet{
            
             if didSelected == true {
                if lastState == true {
                    return
                }
                textColor = UIColor.orangeColor()
                self.transform = CGAffineTransformScale(self.transform, 1.2, 1.2)
                lastState = didSelected
                }
            else{
                textColor = UIColor.whiteColor()
                self.transform = CGAffineTransformIdentity;
                lastState = false
            }
            
        }
    }
  
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.didSelected = false;
        textAlignment = NSTextAlignment.Center
        font = UIFont.systemFontOfSize(14)
        textColor = UIColor.whiteColor()
        self.userInteractionEnabled = true
        let tap :UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(labelClick))
        self.addGestureRecognizer(tap)
    }
    
    func labelClick() {
       self.delegate?.labelClick!(self,tag: self.tag)
        self.didSelected = true
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
